package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {
    public static void shuffle(List<Card> cards){
        Random random =new Random();
        for(int i = cards.size() - 1;i > 0;i--){
            int j = random.nextInt(i);
            Card tmp = cards.get(i);
            cards.set(i,cards.get(j));
            cards.set(j,tmp);


        }

    }

    public static final String SUITS[] = {"♥","♣","♦","♠"};
    public static List<Card> buyCard(){
        List<Card> cards = new ArrayList<>();//用一个链表来存放所有的对象
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j < 14; j++) {
                Card card = new Card(SUITS[i],j);//一张牌是一个对象，
                cards.add(card);

            }
        }
        return cards;


    }


    public static void main(String[] args) {
        List<Card> cards = buyCard();//产生牌
        System.out.println(cards);
        System.out.println("洗牌：");
        shuffle(cards);
        System.out.println(cards);
        System.out.println("揭牌：");

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> hand = new ArrayList<>();//存放三个人的牌
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for(int i = 0; i < 5;i++){
            for (int j = 0; j < 3;j++){
                Card card = cards.remove(0);
                hand.get(j).add(card);

            }
        }
        System.out.println("第一个人的牌：");
        System.out.println(hand1);
        System.out.println("第二个人的牌：");
        System.out.println(hand2);
        System.out.println("第三个人的牌：");
        System.out.println(hand3);
        System.out.println("剩下的牌");
        System.out.println(cards);


    }

}
